﻿<sticky:StickyWindowBase xmlns:sticky="clr-namespace:Squiggle.UI.StickyWindow"
                     x:Class="Squiggle.UI.Windows.SettingsWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Squiggle Settings" Height="380" Width="460" 
    Icon="/Squiggle;component/Images/Chat.ico"             
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:settings="clr-namespace:Squiggle.UI.Settings"
    xmlns:converters="clr-namespace:Squiggle.UI.Converters"
    KeyDown="Window_KeyDown" Loaded="Window_Loaded" ShowInTaskbar="False" 
    WindowStartupLocation="CenterOwner" ResizeMode="NoResize">
    <Window.Resources>
        <SolidColorBrush x:Key="DialogBackground" Color="#FFF0F0F0"/>
        <SolidColorBrush x:Key="WorkAreaBackgroud" Color="#FFD2D8DE"/>
        <ObjectDataProvider x:Key="viewTypes" 
                            ObjectType="{x:Type sys:Enum}"
                            MethodName="GetValues">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="settings:ContactListView" />
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
        <ObjectDataProvider x:Key="sortFields" 
                            ObjectType="{x:Type sys:Enum}"
                            MethodName="GetValues">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="settings:ContactListSortField" />
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
    </Window.Resources>
    <Grid x:Name="LayoutRoot" FlowDirection="{StaticResource flowDirection}">
        <TabControl x:Name="tabs">
            <TabItem Header="{StaticResource SettingsWindow_GeneralTab_Heading}">
                <Grid >
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <TextBlock Grid.Row="0" Margin="5" FontWeight="Bold" Text="{StaticResource SettingsWindow_GeneralTab_SubHeading}" />
                    <Border Grid.Row="1" Background="{StaticResource WorkAreaBackgroud}" BorderBrush="Black" BorderThickness="1" CornerRadius="3" Margin="5">
                        <Grid Margin="10">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <Grid Grid.Row="0" Margin="5,0,0,0"> 
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                
                                <CheckBox Grid.Row="0" Margin="0,0,0,5" 
                                          Content="{StaticResource SettingsWindow_GeneralTab_RunOnStartup}" IsChecked="{Binding Path=GeneralSettings.RunAtStartup}" />
                                <CheckBox Grid.Row="1" Margin="0,0,0,5" 
                                           Content="{StaticResource SettingsWindow_GeneralTab_CloseToTray}" IsChecked="{Binding Path=GeneralSettings.HideToSystemTray}" />
                                <CheckBox Grid.Row="2" Margin="0,0,0,5" 
                                           Content="{StaticResource SettingsWindow_GeneralTab_ShowPopups}" IsChecked="{Binding Path=GeneralSettings.ShowPopups}" />
                                <CheckBox Grid.Row="3" Margin="0,0,0,5" 
                                           Content="{StaticResource SettingsWindow_GeneralTab_AudioAlerts}" IsChecked="{Binding Path=GeneralSettings.AudioAlerts}" />
                                <CheckBox Grid.Row="4" Margin="0,0,0,5" 
                                           Content="{StaticResource SettingsWindow_GeneralTab_StatusLogging}" IsChecked="{Binding Path=GeneralSettings.EnableStatusLogging}" />
                                <CheckBox Grid.Row="5" Margin="0,0,0,5" 
                                           Content="{StaticResource SettingsWindow_GeneralTab_CheckForUpdates}" IsChecked="{Binding Path=GeneralSettings.CheckForUpdates}" />
                            </Grid>
                            <Grid Grid.Row="1" Margin="5,10,0,0">
                                <Grid.RowDefinitions>
                                    <RowDefinition />
                                    <RowDefinition />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="113" />
                                    <ColumnDefinition Width="283" />
                                </Grid.ColumnDefinitions>
                               
                                <TextBlock Grid.Row="1" Text="{StaticResource SettingsWindow_GeneralTab_DownloadsFolder}" Grid.ColumnSpan="2" Margin="0" />
                                <StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Top" Margin="0">
                                    <TextBox x:Name="txtDownloadsFolder" IsReadOnly="True" Text="{Binding Path=GeneralSettings.DownloadsFolder}" Width="200" />
                                    <Button Content="{StaticResource SettingsWindow_GeneralTab_Browse}" Click="btnBrowseDownloadsFolder_Click" Margin="5,0,0,0" />
                                </StackPanel>
                            </Grid>
                        </Grid>
                    </Border>
                    <Grid Grid.Row="2">
                        <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
                            <Button IsDefault="True" Content="{StaticResource Global_OKButton}" Width="70" Click="btnOK_Click" />
                            <Button IsCancel="True" Content="{StaticResource Global_CancelButton}" Width="70" Margin="5,0,0,0" Click="btnCancel_Click" />
                        </StackPanel>
                    </Grid>
                </Grid>
            </TabItem>
            <TabItem x:Name="personalTab" Header="{StaticResource SettingsWindow_PersonalTab_Heading}">
                <Grid >
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <TextBlock Grid.Row="0" Margin="5" FontWeight="Bold" Text="{StaticResource SettingsWindow_PersonalTab_SubHeading}" />
                    <Border Grid.Row="1" Background="{StaticResource WorkAreaBackgroud}" BorderBrush="Black" BorderThickness="1" CornerRadius="3" Margin="5">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <Grid Grid.Row="1" Margin="10">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <TextBlock HorizontalAlignment="Left" Margin="5,0,0,5" 
                                    Text="{StaticResource SettingsWindow_PersonalTab_DisplayName}"/>
                                <TextBox Width="200" Margin="5,0,0,5" 
                                         Grid.Row="1" MaxLength="50" HorizontalAlignment="Left"
                                         Text="{Binding Path=PersonalSettings.DisplayName}" 
                                         Height="22" VerticalAlignment="Top" />
                                <TextBlock HorizontalAlignment="Left" Grid.Row="2"
                                           Margin="5,0,0,5" 
                                           Text="{StaticResource SettingsWindow_PersonalTab_DisplayMessage}"/>
                                <TextBox Width="200" HorizontalAlignment="Left" Grid.Row="3"  MaxLength="150"
                                         Margin="5,0,0,5" Height="22" VerticalAlignment="Top"
                                         Text="{Binding Path=PersonalSettings.DisplayMessage}" />
                                <TextBlock HorizontalAlignment="Left" Grid.Row="4" 
                                           Margin="5,0,0,5" 
                                           Text="{StaticResource SettingsWindow_PersonalTab_EmailAddress}"/>
                                <TextBox Width="200" HorizontalAlignment="Left"
                                         Grid.Row="5" MaxLength="150" Margin="5,0,0,5" 
                                         Text="{Binding Path=PersonalSettings.EmailAddress}" 
                                         Height="22" VerticalAlignment="Top" />
                                <StackPanel Grid.Row="6" Orientation="Horizontal" Margin="5,0,0,5">
                                    <TextBlock Text="{StaticResource SettingsWindow_PersonalTab_IdleTimeout}" />
                                    <TextBox Margin="5,0,0,0" Height="Auto" VerticalAlignment="Top" Width="40" HorizontalAlignment="Left" Text="{Binding Path=PersonalSettings.IdleTimeout}" />
                                    <TextBlock Margin="5,0,0,0">mins</TextBlock>
                                </StackPanel>
                                <CheckBox Content="{StaticResource SettingsWindow_PersonalTab_AutoSignIn}" 
                                          Grid.Row="7" Margin="5,0,0,5"
                                          IsChecked="{Binding Path=PersonalSettings.AutoSignMeIn}" />
                                <CheckBox Content="{StaticResource SettingsWindow_PersonalTab_RememberMe}"
                                          Grid.Row="8" Margin="5,0,0,5"                                      
                                          IsChecked="{Binding Path=PersonalSettings.RememberMe}"/>
                                <StackPanel Grid.RowSpan="4" HorizontalAlignment="Left" Margin="282,0,0,0">
                                    <Border BorderBrush="Black" BorderThickness=".5" Height="81" >
                                        <Image VerticalAlignment="Top" Width="98" Grid.Row="1"
                                           Source="{Binding PersonalSettings.DisplayImage}" />
                                    </Border>
                                    <StackPanel HorizontalAlignment="Right" Margin="0,5,0,0" Orientation="Horizontal">
                                        <Button Content="{StaticResource SettingsWindow_PersonalTab_DisplayImage}" Height="23" 
                                                Name="btnSetDisplayImage" Click="btnSetDisplayImage_Click" />
                                        <Button Name="btnClearDisplayImage" Click="btnClearDisplayImage_Click">
                                            <Button.Style>
                                                <Style TargetType="Button" BasedOn="{StaticResource CloseButtonStyle}">
                                                    <Style.Triggers>
                                                        <DataTrigger Binding="{Binding PersonalSettings.DisplayImage}" Value="{x:Null}">
                                                            <Setter Property="Visibility" Value="Collapsed" />
                                                        </DataTrigger>
                                                    </Style.Triggers>
                                                </Style>
                                            </Button.Style>
                                        </Button>
                                    </StackPanel>
                                </StackPanel>
                            </Grid>
                        </Grid>
                    </Border>
                    <Grid Grid.Row="2">
                        <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
                            <Button Content="{StaticResource Global_OKButton}" Width="70" Click="btnOK_Click" />
                            <Button Content="{StaticResource Global_CancelButton}" Width="70" Margin="5,0,0,0" Click="btnCancel_Click" />
                        </StackPanel>
                    </Grid>
                </Grid>
            </TabItem>
            <TabItem Header="{StaticResource SettingsWindow_ChatTab_Heading}">
                <Grid >
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <TextBlock Grid.Row="0" Margin="5" FontWeight="Bold" Text="{StaticResource SettingsWindow_ChatTab_SubHeading}" />
                    <Border Grid.Row="1" Background="{StaticResource WorkAreaBackgroud}" BorderBrush="Black" BorderThickness="1" CornerRadius="3" Margin="5">
                        <Grid Margin="10">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <CheckBox Grid.Row="0" Margin="5,0,0,5" Content="{StaticResource SettingsWindow_ChatTab_ShowEmoticons}" IsChecked="{Binding Path=ChatSettings.ShowEmoticons}" />
                            <CheckBox Grid.Row="1" Margin="5,0,0,5" Content="{StaticResource SettingsWindow_ChatTab_EnableLogging}" IsChecked="{Binding Path=ChatSettings.EnableLogging}" />
                            <CheckBox Grid.Row="2" Margin="5,0,0,5" Content="{StaticResource SettingsWindow_ChatTab_SpellCheck}" IsChecked="{Binding Path=ChatSettings.SpellCheck}" />
                            <CheckBox Grid.Row="3" Margin="5,0,0,5" Content="{StaticResource SettingsWindow_ChatTab_StealFocusOnNewMessage}" IsChecked="{Binding Path=ChatSettings.StealFocusOnNewMessage}" />
                            <CheckBox Grid.Row="4" Margin="5,0,0,5" Content="{StaticResource SettingsWindow_ChatTab_ClearChatOnWindowClose}" IsChecked="{Binding Path=ChatSettings.ClearChatOnWindowClose}" />
                        </Grid>
                    </Border>
                    <Grid Grid.Row="2">
                        <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
                            <Button Content="{StaticResource Global_OKButton}" Width="70" Click="btnOK_Click" />
                            <Button Content="{StaticResource Global_CancelButton}" Width="70" Margin="5,0,0,0" Click="btnCancel_Click" />
                        </StackPanel>
                    </Grid>
                </Grid>
            </TabItem>
            <TabItem Header="{StaticResource SettingsWindow_ContactsTab_Heading}">
                <Grid >
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <TextBlock Grid.Row="0" Margin="5" FontWeight="Bold" Text="{StaticResource SettingsWindow_ContactsTab_SubHeading}" />
                    <Border Grid.Row="1" Background="{StaticResource WorkAreaBackgroud}" BorderBrush="Black" BorderThickness="1" CornerRadius="3" Margin="5">
                        <Grid Margin="10">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="113" />
                                <ColumnDefinition Width="283" />
                            </Grid.ColumnDefinitions>
                            <CheckBox Grid.Row="0" Grid.ColumnSpan="2" Margin="5,0,0,5" Content="{StaticResource SettingsWindow_ContactsTab_ShowGroupedContacts}" IsChecked="{Binding Path=ContactSettings.GroupContacts}" />
                            <CheckBox Grid.Row="1" Grid.ColumnSpan="2" Margin="5,0,0,5" Content="{StaticResource SettingsWindow_ContactsTab_ShowOfflineContacts}" IsChecked="{Binding Path=ContactSettings.ShowOfflineContacts}" />
                            <TextBlock Grid.Row="2" Text="{StaticResource SettingsWindow_ContactsTab_SortBy}" Grid.ColumnSpan="2" Margin="10,10,226,0" />
                            <ComboBox Grid.Row="2" Grid.Column="1" HorizontalAlignment="Left"
                                      VerticalAlignment="Top" Width="100" Margin="0,10,0,0"
                                      ItemsSource="{Binding Source={StaticResource sortFields}}"
                                      x:Name="cmbSortField">
                                <ComboBox.Resources>
                                    <DataTemplate DataType="{x:Type settings:ContactListSortField}">
                                        <TextBlock Text="{Binding Converter={x:Static converters:EnumValueConverter.Instance}}" />
                                    </DataTemplate>
                                </ComboBox.Resources>
                            </ComboBox>
                            <TextBlock Grid.Row="3" Text="{StaticResource SettingsWindow_ContactsTab_View}" Grid.ColumnSpan="2" Margin="10,10,226,0" />
                            <ComboBox Grid.Row="3" Grid.Column="1" HorizontalAlignment="Left" 
                                      VerticalAlignment="Top" Width="100" Margin="0,10,0,0" 
                                      ItemsSource="{Binding Source={StaticResource viewTypes}}"
                                      x:Name="cmbContactsView">
                                <ComboBox.Resources>
                                    <DataTemplate DataType="{x:Type settings:ContactListView}">
                                        <TextBlock Text="{Binding Converter={x:Static converters:EnumValueConverter.Instance}}" />
                                    </DataTemplate>
                                </ComboBox.Resources>
                            </ComboBox>
                        </Grid>
                    </Border>
                    <Grid Grid.Row="2">
                        <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
                            <Button Content="{StaticResource Global_OKButton}" Width="70" Click="btnOK_Click" />
                            <Button Content="{StaticResource Global_CancelButton}" Width="70" Margin="5,0,0,0" Click="btnCancel_Click" />
                        </StackPanel>
                    </Grid>
                </Grid>
            </TabItem>
            <TabItem Header="{StaticResource SettingsWindow_ConnectionTab_Heading}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <TextBlock Grid.Row="0" Margin="5" FontWeight="Bold" Text="{StaticResource SettingsWindow_ConnectionTab_SubHeading}" />
                    <Border Grid.Row="1" Background="{StaticResource WorkAreaBackgroud}" BorderBrush="Black" BorderThickness="1" CornerRadius="3" Margin="5">
                        <Grid Margin="10">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="64*" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="138" />
                                <ColumnDefinition Width="200" />
                                <ColumnDefinition Width="58*" />
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Row="4" Grid.Column="0" Text="{StaticResource SettingsWindow_ConnectionTab_PresenceAddress}" />
                            <TextBox Grid.Row="4" Grid.Column="1" Text="{Binding Path=ConnectionSettings.PresenceAddress}" Margin="0,0,0,5" />
                            <Button Grid.Row="4" Grid.Column="2" Content="{StaticResource SettingsWindow_ConnectionTab_Reset}" HorizontalAlignment="Left" Click="btnPresenceAddressReset_Click" />
                            <TextBlock Grid.Row="5" Grid.Column="0" Text="{StaticResource SettingsWindow_ConnectionTab_PresencePort}" />
                            <TextBox Grid.Row="5" Grid.Column="1" Text="{Binding Path=ConnectionSettings.PresencePort}" Margin="0,0,0,5"/>
                            <TextBlock Grid.Row="6" Grid.Column="0" Text="{StaticResource SettingsWindow_ConnectionTab_ChatPort}" />
                            <TextBox Grid.Row="6" Grid.Column="1" Text="{Binding Path=ConnectionSettings.ChatPort}" Margin="0,0,0,5"/>
                            <TextBlock Grid.Row="7" Grid.Column="0" Text="{StaticResource SettingsWindow_ConnectionTab_KeepAliveTime}" />
                            <StackPanel Grid.Row="7" Grid.Column="1" Orientation="Horizontal">
                                <TextBox Text="{Binding Path=ConnectionSettings.KeepAliveTime}" Width="80" Margin="0,0,5,5" HorizontalAlignment="Left" />
                                <TextBlock>secs</TextBlock>
                            </StackPanel>
                            <TextBlock Grid.Row="8" Grid.Column="0" Text="{StaticResource SettingsWindow_ConnectionTab_BindToIP}" />
                            <ComboBox Grid.Row="8" Grid.Column="1" ItemsSource="{Binding Path=ConnectionSettings.AllIPs}" SelectedValue="{Binding Path=ConnectionSettings.BindToIP}" Width="150" HorizontalAlignment="Left" Margin="0,0,0,5"/>
                            
                        </Grid>
                    </Border>
                    <Grid Grid.Row="2">
                        <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
                            <Button Content="{StaticResource Global_OKButton}" Width="70" Click="btnOK_Click" />
                            <Button Content="{StaticResource Global_CancelButton}" Width="70" Margin="5,0,0,0" Click="btnCancel_Click" />
                        </StackPanel>
                    </Grid>
                </Grid>
            </TabItem>
        </TabControl>
    </Grid>
</sticky:StickyWindowBase>
